import Vue from 'vue'
import VueRouter from 'vue-router'
import menu from '../views/menu.vue'
import index from '../views/index.vue'
import store from '../views/store.vue'
import activity from '../views/activity.vue'
import personal from '../views/personal.vue'
import selective from '../views/selective/selective.vue'
import discounts from '../views/discounts/discounts.vue'
import login from '../views/login.vue'
import union from '../views/optional/union.vue'
import fucai3d from '../views/optional/fucai3d.vue'
import qicai from '../views/optional/qicai.vue'
import runlottery from '../views/runlottery/runlottery.vue'
import order from '../views/order/order.vue'
import invoice from '../views/order/invoice.vue'
import record from '../views/record.vue'
import amend from '../views/amend.vue'
import news from '../views/news.vue'
import nickname from '../views/nickname/nickname.vue'
import headimg from '../views/nickname/headimg.vue'

Vue.use(VueRouter)

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
const routes = [
  {
    path: '/',
    name: 'menu',
    component: menu,
		redirect:'/index',
		children:[{
			path: '/index',
			name: 'index',
			component: index,
			meta:{
				title:'首页'
			},
		},
		{
			path: '/store',
			name: 'store',
			component: store,
			meta:{
				title:'彩民商城'
			},
		},
		{
			path: '/activity',
			name: 'activity',
			component: activity,
			meta:{
				title:'活动资讯'
			},
		},
		{
			path: '/personal',
			name: 'personal',
			component: personal,
			meta:{
				title:'我的'
			},
		}]
  },
	{
		path: '/selective',
		name: 'selective',
		component: selective,
		meta:{
			title:'快速机选',
			keepAlive: false
		}
	},
	{
		path: '/discounts',
		name: 'discounts',
		meta:{
			title:'优惠券'
		},
		component: discounts
	},
	{
		path: '/login',
		name: 'login',
		component: login
	},
	{
		path: '/union',
		name: 'union',
		meta:{
			title:'双色球'
		},
		component: union
	},
	{
		path: '/fucai3d',
		name: 'fucai3d',
		meta:{
			title:'福彩3D'
		},
		component: fucai3d
	},
	{
		path: '/qicai',
		name: 'qicai',
		component: qicai,
		meta:{
			title:'七乐彩'
		},
	},
	{
		path: '/runlottery',
		name: 'runlottery',
		meta:{
			title:'开奖信息'
		},
		component: runlottery
	},
	{
		path: '/record',
		name: 'record',
		meta:{
			title:'购买记录'
		},
		component: record
	},
	{
		path: '/order',
		name: 'order',
		meta:{
			title:'订单详情'
		},
		component: order
	},
	{
		path: '/amend',
		name: 'amend',
		meta:{
			title:'修改信息'
		},
		component: amend
	},
	{
		path: '/invoice',
		name: 'invoice',
		meta:{
			title:'支付成功'
		},
		component: invoice
	},
	{
		path: '/news',
		name: 'news',
		meta:{
			title:'资讯详情'
		},
		component: news
	},
	{
		path: '/nickname',
		name: 'nickname',
		meta:{
			title:'修改名称'
		},
		component: nickname
	},
	{
		path: '/headimg',
		name: 'headimg',
		meta:{
			title:'更换头像'
		},
		component: headimg
	}
]

const router = new VueRouter({
	// mode: "history",
  routes
})
router.beforeEach((to, from, next) => {
  //修改标题
  if (to.meta.title) {
    document.title = to.meta.title;
  }
  next();
});
// router.beforeEach((to,from,next)=>{
// 	if(to.path==='/login'){
// 		return next()
// 	}
// 	let tokenter=window.sessionStorage.getItem('token')
// 	if(!tokenter){
// 		return next('/login')
// 	}else{
// 		return next()
// 	}
// })
export default router
